<?php
//初始化
define('IN_WEB',true);
define("IS_PRODUCTION", false); //是否产品模式
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(30);   //设置脚本执行时间
mb_internal_encoding("UTF-8");  //设置编码
date_default_timezone_set('Asia/Shanghai');//设置时区
//过滤
$_POST=filter_input_array(INPUT_POST,FILTER_SANITIZE_MAGIC_QUOTES);	
$_GET=filter_input_array(INPUT_GET,FILTER_SANITIZE_MAGIC_QUOTES);

//路径
define('ROOT', dirname(__FILE__));
define('PATH_CFG', ROOT.'/config');
define('PATH_CORE', ROOT.'/core');
define('PATH_LIB', ROOT.'/lib');
define('PATH_UTIL', ROOT.'/util');
define('PATH_API', ROOT.'/api');
//define('PATH_APP', ROOT.'/app');
define('PATH_DATA', ROOT.'/data');

//加载
require_once(PATH_CORE.'/factory/CoreFactory.php');
require_once(PATH_CORE.'/factory/ProxyFactory.php');
require_once(PATH_CORE.'/factory/ServiceFactory.php');
require_once(PATH_CORE.'/factory/ModelFactory.php');
require_once(PATH_API.'/Gateway.php');

//自动加载
$autoloadClasses=array(
	'BaseProxy'=>PATH_CORE.'/base/BaseProxy.php',
	'BaseModel'=>PATH_CORE.'/base/BaseModel.php',
	'AbstractValidator'=>PATH_CORE.'/base/AbstractValidator.php',
	'AbstractLogger'=>PATH_CORE.'/base/AbstractLogger.php',
	'Validator'=>PATH_CORE.'/validator/Validator.php',
	'SaeTOAuth'=>PATH_LIB.'/sina/SaeTOAuth.php',
	'SaeTClient'=>PATH_LIB.'/sina/SaeTClient.php',
	'SaeTOAuthV2'=>PATH_LIB.'/sina/saetv2.ex.class.php',
	'SaeTClientV2'=>PATH_LIB.'/sina/saetv2.ex.class.php',	
);
function autoload($className){
	global $autoloadClasses;
	if(isset($autoloadClasses[$className])){
		include($autoloadClasses[$className]);
		return true;
	}else return false;
}
spl_autoload_register('autoload');

//错误信息
function error_handle($errno, $errstr, $errfile, $errline) {
	switch($errno) {
		case E_NOTICE:
		case E_USER_NOTICE:
		case E_WARNING:
		case E_USER_WARNING:
			$errtype='Warning';
			break;
		default:
			$errtype='Error';
			break;
	}
	if($errtype=='Warning'){
		CoreFactory::log()->warn($errtype.': '.$errstr.' in '.$errfile.' on line '.$errline);
	}else if($errtype=='Error'){
		CoreFactory::log()->error($errtype.': '.$errstr.' in '.$errfile.' on line '.$errline);
		exit;
	}
}
if(IS_PRODUCTION===true) set_error_handler(error_handle,30711);
